package com.qf.emp.controller;

import com.qf.emp.entity.Page;
import com.qf.emp.entity.Profile;
import com.qf.emp.service.ProfileService;
import com.qf.emp.service.UserService;
import com.qf.emp.service.impl.ProfileServiceImpl;
import com.qf.emp.service.impl.UserServiceImpl;
import com.qf.emp.utils.Constants;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/profile")
public class Profilecontroller extends BaseServlet{

    public String show(HttpServletRequest request, HttpServletResponse response){
        System.out.println("登录成功！查询所有！");
        String pageIndex = request.getParameter("pageIndex");
        if (pageIndex == null){
            pageIndex = "1";
        }

        Page page = new Page(Integer.valueOf(pageIndex));
        ProfileService profileService = new ProfileServiceImpl();
        List<Profile> pers = profileService.showAll(page);
        request.setAttribute("pers", pers);
        request.setAttribute("page",page);
        return Constants.FORWARD + "/list.jsp";
    }
    public String showDetail(HttpServletRequest request, HttpServletResponse response){
        Integer id = Integer.valueOf(request.getParameter("id"));
        ProfileService profileService = new ProfileServiceImpl();
        Profile per = profileService.showPer(id);
        if (per !=null){
            return Constants.FORWARD + "detail.jps";
        }
        return Constants.FORWARD + "error.jsp";
    }

    public String updatePer(HttpServletRequest request, HttpServletResponse response){
        return null;
    }

}
